package basic.JUC.print100;

import java.util.concurrent.locks.LockSupport;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/13 17:50
 * @描述 暂无
 */
public class LockSupportPrint {
    static Thread t1=null;
    static Thread t2 = null;
    public static void main(String[] args) {
        print();
    }
    public static void print(){

        char[] a1 = "1234567".toCharArray();
        char[] a2 = "ABCDEFG".toCharArray();

        t1 = new Thread(() -> {
            for(char c : a1){
                System.out.print(c);
                LockSupport.unpark(t2);   //释放t2线程 设置锁标志位
                LockSupport.park();   //阻塞当前线程
            }
        },"t1");

        t2 = new Thread(() -> {
            for(char c : a2){
                LockSupport.park();      //阻塞当前线程
                System.out.print(c);
                LockSupport.unpark(t1);       //释放t1线程
            }
        },"t2");

        t1.start();
        t2.start();
    }

}
